<?php 
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' ); 
mm_showMyFileName( __FILE__ );
		$dbc = new ps_DB( ) ; // Carriers

		$ps_id_relais = vmGet( $_REQUEST, 'id_relais' ) ;
		$ps_popup_relais = vmGet( $_REQUEST, 'popup_relais' ) ;
		$ps_largeur = vmGet( $_REQUEST, 'largeur' ) ;
		$ps_hauteur = vmGet( $_REQUEST, 'hauteur' ) ;
		$d['ship_to_info_id'] = vmGet( $_REQUEST, 'ship_to_info_id' ) ;
		$q  = "SELECT * FROM #__{vm}_user_info, #__{vm}_country WHERE user_info_id='" . $d["ship_to_info_id"]."' AND ( country=country_2_code OR country=country_3_code)";
		$dbc->query( $q ) ;
		$dbc->next_record() ;
		$country = $dbc->f( "country_2_code" ) ;
		
// Read the mondialrelay configuration file
		require_once(CLASSPATH ."shipping/mondialrelay.cfg.php");

// On met en place les paramètres de la requète
		$params = array(
					   'Enseigne'  => MR_ENSEIGNE,
					   'Num'       => $ps_id_relais,
					   'Pays'      => $country
		);

		//On crée le code de sécurité
		$code = implode("",$params);
		$code .= MR_CLE;
		
		
		//On le rajoute aux paramètres
		$params["Security"] = strtoupper(md5($code));
		//echo 'Security: '.$params["Security"];
		// On se connecte
		$client = new SoapClient("http://www.mondialrelay.fr/WebService/Web_Services.asmx?WSDL");
		
		// Et on effectue la requète
		$detail_pointrelais = $client->WSI2_DetailPointRelais($params)->WSI2_DetailPointRelaisResult;

	if( vmIsJoomla('1.0') && mosGetParam($_REQUEST,'option') != VM_COMPONENT_NAME) {
	// This can only be a call from a module or mambot
	// In Joomla 1.0 it is not possible to add a JS or CSS into the HEAD from a module or content mambot,
	// using addcustomheadtag, that's why we just print the tags here
	echo vmCommonHTML::linkTag(VM_THEMEURL.'pointsrelais.css');
} else {
	$vm_mainframe->addStyleSheet( VM_THEMEURL.'pointsrelais.css' );
}
?>
<div id="detailsPointRelais"">
    <div class="colonne-gauche">
        <h1><?php echo 'Votre' ?> <span style="font-weight: bold;"><?php echo 'Point Relais' ?></span></h1>
        <div class="adresse">
            <h2><?php echo $detail_pointrelais->LgAdr1 ?></h2>
            <?php if($detail_pointrelais->LgAdr2) : ?>
                <p><?php echo '<p>' . strtolower($detail_pointrelais->LgAdr2) ?></p>
            <?php endif; ?>
            <?php if($detail_pointrelais->LgAdr3) : ?>
                <p><?php echo strtolower($detail_pointrelais->LgAdr3) ?></p>
            <?php endif; ?>
            <?php if($detail_pointrelais->LgAdr4) : ?>
                <p><?php echo strtolower($detail_pointrelais->LgAdr4) ?></p>
            <?php endif; ?>
            <p><?php echo $detail_pointrelais->CP . " " . $detail_pointrelais->Ville; ?></p>
            <div class="situation">
                <p><?php echo $detail_pointrelais->Localisation1 ?></p>
                <p><?php echo $detail_pointrelais->Localisation2 ?></p>
            </div>
        </div>
    </div>
    <div class="colonne-droite">
        <?php if($detail_pointrelais->URL_Photo) : ?>
        <div class="photo">
            <img src="<?php echo $detail_pointrelais->URL_Photo ?>" alt="<?php echo $detail_pointrelais->LgAdr1 ?>" />
        </div>
        <?php endif; ?>
        <div class="horaires">
            <h2><?php echo 'Horaires d\'ouverture' ?></h2>
            <table>
                <tr>
                    <td class="jour"><?php echo 'Lundi' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Lundi->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Lundi->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Lundi->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Lundi->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Lundi->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Lundi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Lundi->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Lundi->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Lundi->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Lundi->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="jour"><?php echo 'Mardi' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Mardi->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mardi->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Mardi->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mardi->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Mardi->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Mardi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mardi->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Mardi->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mardi->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Mardi->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="jour"><?php echo 'Mercredi' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Mercredi->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mercredi->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Mercredi->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mercredi->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Mercredi->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Mercredi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mercredi->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Mercredi->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Mercredi->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Mercredi->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="jour"><?php echo 'Jeudi' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Jeudi->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Jeudi->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Jeudi->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Jeudi->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Jeudi->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Jeudi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Jeudi->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Jeudi->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Jeudi->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Jeudi->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="jour"><?php echo 'Vendredi' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Vendredi->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Vendredi->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Vendredi->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Vendredi->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Vendredi->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Vendredi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Vendredi->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Vendredi->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Vendredi->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Vendredi->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <tr>
                    <td class="jour"><?php echo 'Samedi' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Samedi->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Samedi->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Samedi->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Samedi->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Samedi->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Samedi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Samedi->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Samedi->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Samedi->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Samedi->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php try { $detail_pointrelais->Horaires_Dimanche; ?>
                <tr>
                    <td class="jour"><?php echo 'Dimanche' ?></td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Dimanche->string[0] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Dimanche->string[0],-4,2) . "h". substr($detail_pointrelais->Horaires_Dimanche->string[0],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Dimanche->string[1],-4,2) . "h". substr($detail_pointrelais->Horaires_Dimanche->string[1],-2); ?>
                        <?php endif; ?>
                    </td>
                    <td>
                        <?php if($detail_pointrelais->Horaires_Lundi->string[2] != 0) : ?>
                            <?php echo substr($detail_pointrelais->Horaires_Dimanche->string[2],-4,2) . "h". substr($detail_pointrelais->Horaires_Dimanche->string[2],-2) . " - "; ?>
                            <?php echo substr($detail_pointrelais->Horaires_Dimanche->string[3],-4,2) . "h". substr($detail_pointrelais->Horaires_Dimanche->string[3],-2); ?>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php
                }
                catch (Exception $e) {
                    $errors[] = $e->getMessage();
                }?>
            </table>
	<div class="fermer"><a href="#" onclick="window.close(); return false;">Fermer</a></div>
	</body>
</html>
